package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.entity.HomeCarousel;
import com.lanou.service.HomeCarouselService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName HomeCarouselController
 * @Description TODO
 * @Author cuipengwei
 * @Date 2025年08月15日 10:12
 * @Version 1.0
 */
@RestController
@RequestMapping("carousel")
public class HomeCarouselController {
    @Autowired
    private HomeCarouselService homeCarouselService;

    //增加
    @PostMapping
    public R add(@RequestBody HomeCarousel homeCarousel) {
        Integer i = homeCarouselService.addHomeCarousel(homeCarousel);
        return R.ok(i);
    }
    //删除
    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") Integer id){
        Integer i = homeCarouselService.deleteHomeCarousel(id);
        return R.ok(i);
    }
    //分页查询全部
    @GetMapping("all")
    public R getHomeCarouselList(HomeCarousel homeCarousel,
                                 @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                 @RequestParam(required = false,defaultValue = "5") Integer pageSize){
        PageInfo<HomeCarousel> homeCarouselPageInfo = homeCarouselService.selectHomeCarousel(homeCarousel, pageNum, pageSize);
        return R.ok(homeCarouselPageInfo);

    }
}
